<template>
  <div class="git-memo">
    <div class="git-memo-container">
      <h1 class="title">Git 备忘录</h1>
      <p class="description">Git是一种去中心化的版本管理软件，使用批处理方式，您可以快速访问常用的git命令。</p>

      <div class="memo-sections">
        <!-- 一个简单的提交过程 -->
        <section class="memo-section">
          <h2>一个简单的提交过程</h2>
          <div class="command-group">
            <div class="command-item">
              <code>git add .</code>
              <span class="description">添加所有更改到暂存区</span>
            </div>
            <div class="command-item">
              <code>git commit -m "提交信息"</code>
              <span class="description">提交更改到本地仓库</span>
            </div>
            <!-- 同步远程仓库代码 -->
            <div class="command-item">
              <code>git pull</code>
              <span class="description">如果远程仓库有更新 拉取远程仓库代码 并合并到本地仓库</span>
            </div>
            <div class="command-item">
              <code>git push</code>
              <span class="description">推送更改到远程仓库</span>
            </div>
          </div>
        </section>

        <!-- 配置部分 -->
        <section class="memo-section">
          <h2>配置</h2>
          <div class="command-group">
            <h3>查看配置</h3>
            <div class="command-item">
              <code>git config --list</code>
              <span class="description">列出所有Git配置项</span>
            </div>
            <div class="command-item">
              <code>git config --global --list</code>
              <span class="description">只列出全局配置项</span>
            </div>
            <h3>设置全局配置</h3>
            <div class="command-item">
              <code>git config --global user.name "[name]"</code>
              <span class="description">设置Git提交时的用户名</span>
            </div>
            <div class="command-item">
              <code>git config --global user.email "[email]"</code>
              <span class="description">设置Git提交时的邮箱地址</span>
            </div>
            <div class="command-item">
              <code>git config --global core.editor "[editor]"</code>
              <span class="description">设置默认文本编辑器</span>
            </div>
            <div class="command-item">
              <code>git config --global color.ui true</code>
              <span class="description">启用Git命令的颜色输出</span>
            </div>
          </div>
        </section>

        <!-- 开始部分 -->
        <section class="memo-section">
          <h2>开始</h2>
          <div class="command-group">
            <h3>创建仓库</h3>
            <div class="command-item">
              <code>git init</code>
              <span class="description">在当前目录初始化一个新的Git仓库</span>
            </div>
            <div class="command-item">
              <code>git clone [url]</code>
              <span class="description">克隆远程仓库到本地</span>
            </div>
            <div class="command-item">
              <code>git clone [url] [folder-name]</code>
              <span class="description">克隆到指定文件夹</span>
            </div>
          </div>
        </section>

        <!-- 暂存和提交部分 -->
        <section class="memo-section">
          <h2>暂存和提交</h2>
          <div class="command-group">
            <h3>查看状态</h3>
            <div class="command-item">
              <code>git status</code>
              <span class="description">查看工作区和暂存区的状态</span>
            </div>
            <div class="command-item">
              <code>git diff</code>
              <span class="description">查看未暂存的更改</span>
            </div>

            <h3>添加文件到暂存区</h3>
            <div class="command-item">
              <code>git add [file]</code>
              <span class="description">添加指定文件到暂存区</span>
            </div>
            <div class="command-item">
              <code>git add .</code>
              <span class="description">添加所有更改到暂存区</span>
            </div>

            <h3>提交更改</h3>
            <div class="command-item">
              <code>git commit -m "[message]"</code>
              <span class="description">提交暂存区的更改</span>
            </div>
            <div class="command-item">
              <code>git commit -am "[message]"</code>
              <span class="description">直接提交已跟踪文件的更改（跳过暂存区）</span>
            </div>
          </div>
        </section>

        <!-- 分支操作 -->
        <section class="memo-section">
          <h2>分支操作</h2>
          <div class="command-group">
            <h3>分支管理</h3>
            <div class="command-item">
              <code>git branch</code>
              <span class="description">列出所有本地分支</span>
            </div>
            <div class="command-item">
              <code>git branch -r</code>
              <span class="description">列出所有远程分支</span>
            </div>
            <div class="command-item">
              <code>git branch -a</code>
              <span class="description">列出所有本地和远程分支</span>
            </div>
            <div class="command-item">
              <code>git branch -d [branch-name]</code>
              <span class="description">删除本地分支</span>
            </div>
            <div class="command-item">
              <code>git push origin --delete [branch-name]</code>
              <span class="description">删除远程分支</span>
            </div>
            <h3>分支切换</h3>
            <div class="command-item">
              <code>git switch [branch-name]</code>
              <span class="description">切换到指定分支（新版Git推荐使用）</span>
            </div>
            <div class="command-item">
              <code>git switch -c [branch-name]</code>
              <span class="description">创建并切换到新分支（新版Git推荐使用）</span>
            </div>
          </div>
        </section>

        <!-- 日志和历史部分（新增） -->
        <section class="memo-section">
          <h2>日志和历史</h2>
          <div class="command-group">
            <h3>查看提交历史</h3>
            <div class="command-item">
              <code>git log</code>
              <span class="description">查看提交历史</span>
            </div>
            <div class="command-item">
              <code>git log --oneline</code>
              <span class="description">以简洁的一行格式查看提交历史</span>
            </div>
            <div class="command-item">
              <code>git log --graph --oneline --decorate</code>
              <span class="description">以图形方式查看分支合并历史</span>
            </div>
            <div class="command-item">
              <code>git log -p [file]</code>
              <span class="description">查看指定文件的修改历史</span>
            </div>
            <div class="command-item">
              <code>git blame [file]</code>
              <span class="description">查看文件的每一行是谁修改的</span>
            </div>
          </div>
        </section>

        <!-- 标签管理（新增） -->
        <section class="memo-section">
          <h2>标签管理</h2>
          <div class="command-group">
            <h3>创建标签</h3>
            <div class="command-item">
              <code>git tag [tag-name]</code>
              <span class="description">在当前提交上创建标签</span>
            </div>
            <div class="command-item">
              <code>git tag -a [tag-name] -m "[message]"</code>
              <span class="description">创建带有说明的标签</span>
            </div>
            <div class="command-item">
              <code>git tag -a [tag-name] [commit-id]</code>
              <span class="description">在指定的提交上创建标签</span>
            </div>
            <h3>查看和删除标签</h3>
            <div class="command-item">
              <code>git tag</code>
              <span class="description">列出所有标签</span>
            </div>
            <div class="command-item">
              <code>git show [tag-name]</code>
              <span class="description">查看标签信息</span>
            </div>
            <div class="command-item">
              <code>git tag -d [tag-name]</code>
              <span class="description">删除本地标签</span>
            </div>
            <div class="command-item">
              <code>git push origin [tag-name]</code>
              <span class="description">推送标签到远程</span>
            </div>
          </div>
        </section>

        <!-- 远程操作 -->
        <section class="memo-section">
          <h2>远程操作</h2>
          <div class="command-group">
            <h3>远程仓库</h3>
            <div class="command-item">
              <code>git remote -v</code>
              <span class="description">查看远程仓库信息</span>
            </div>
            <div class="command-item">
              <code>git push origin [branch-name]</code>
              <span class="description">推送分支到远程仓库</span>
            </div>
            <div class="command-item">
              <code>git pull origin [branch-name]</code>
              <span class="description">拉取远程分支并合并</span>
            </div>
            <div class="command-item">
              <code>git fetch origin</code>
              <span class="description">获取远程仓库更新</span>
            </div>
          </div>
        </section>

        <!-- 撤销操作 -->
        <section class="memo-section">
          <h2>撤销操作</h2>
          <div class="command-group">
            <h3>撤销修改</h3>
            <div class="command-item">
              <code>git checkout -- [file]</code>
              <span class="description">撤销工作区的修改</span>
            </div>
            <div class="command-item">
              <code>git reset HEAD [file]</code>
              <span class="description">撤销暂存区的修改</span>
            </div>
            <div class="command-item">
              <code>git commit --amend</code>
              <span class="description">修改最后一次提交</span>
            </div>
            <div class="command-item">
              <code>git reset --hard HEAD^</code>
              <span class="description">回退到上一个版本</span>
            </div>
            <div class="command-item">
              <code>git revert [commit]</code>
              <span class="description">创建一个新提交来撤销指定提交</span>
            </div>
          </div>
        </section>

        <!-- 高级操作 -->
        <section class="memo-section">
          <h2>高级操作</h2>
          <div class="command-group">
            <h3>合并与变基</h3>
            <div class="command-item">
              <code>git merge [branch]</code>
              <span class="description">合并指定分支到当前分支</span>
            </div>
            <div class="command-item">
              <code>git merge --no-ff [branch]</code>
              <span class="description">禁用快进方式合并，总是创建新的提交</span>
            </div>
            <div class="command-item">
              <code>git rebase [branch]</code>
              <span class="description">变基操作，使提交历史更加整洁</span>
            </div>
            <div class="command-item">
              <code>git rebase -i HEAD~[n]</code>
              <span class="description">交互式变基，可以修改、合并、删除提交</span>
            </div>
            <h3>暂存工作区</h3>
            <div class="command-item">
              <code>git stash save "[message]"</code>
              <span class="description">暂存工作区并添加说明</span>
            </div>
            <div class="command-item">
              <code>git stash list</code>
              <span class="description">查看所有暂存</span>
            </div>
            <div class="command-item">
              <code>git stash apply stash@{n}</code>
              <span class="description">应用指定的暂存</span>
            </div>
            <div class="command-item">
              <code>git stash drop stash@{n}</code>
              <span class="description">删除指定的暂存</span>
            </div>
            <h3>子模块</h3>
            <div class="command-item">
              <code>git submodule add [url] [path]</code>
              <span class="description">添加子模块</span>
            </div>
            <div class="command-item">
              <code>git submodule update --init --recursive</code>
              <span class="description">初始化并更新所有子模块</span>
            </div>
          </div>
        </section>

        <!-- 故障排除（新增） -->
        <section class="memo-section">
          <h2>故障排除</h2>
          <div class="command-group">
            <h3>查看和修复</h3>
            <div class="command-item">
              <code>git fsck</code>
              <span class="description">检查仓库的完整性</span>
            </div>
            <div class="command-item">
              <code>git reflog</code>
              <span class="description">查看所有操作历史，包括已经删除的提交</span>
            </div>
            <div class="command-item">
              <code>git gc</code>
              <span class="description">压缩和清理仓库</span>
            </div>
            <div class="command-item">
              <code>git prune</code>
              <span class="description">删除无用的对象</span>
            </div>
          </div>
        </section>
      </div>
    </div>
  </div>
</template>

<script setup>
// 组件逻辑
</script>

<style scoped>
.git-memo {
  width: 100%;
  margin: 0 auto;
  padding: 20px;
  height: calc(100vh - 100px);
  overflow-y: auto;
}

.git-memo-container {
  max-width: 1000px;
  margin: 0 auto;
}

.title {
  font-size: 2.5rem;
  color: #2c3e50;
  margin-bottom: 1rem;
}

.description {
  color: #666;
  margin-bottom: 2rem;
}

.memo-sections {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
  gap: 2rem;
}

.memo-section {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  min-width: 400px;
  max-width: 100%;
}

.memo-section h2 {
  color: #2c3e50;
  font-size: 1.5rem;
  margin-bottom: 1rem;
  border-bottom: 2px solid #e9ecef;
  padding-bottom: 0.5rem;
}

.command-group {
  margin-bottom: 1.5rem;
}

.command-group h3 {
  color: #495057;
  font-size: 1.1rem;
  margin: 1rem 0 0.5rem;
}

.command-item {
  margin: 0.5rem 0;
  padding: 0.5rem;
  background: #fff;
  border-radius: 4px;
  border: 1px solid #e9ecef;
  overflow-x: auto;
}

.command-item code {
  display: block;
  padding: 0.5rem;
  background: #2c3e50;
  color: #fff;
  border-radius: 4px;
  font-family: 'Courier New', Courier, monospace;
  margin-bottom: 0.5rem;
  white-space: pre;
  overflow-x: auto;
}

.command-item .description {
  font-size: 0.9rem;
  color: #666;
}

@media (max-width: 768px) {
  .memo-sections {
    grid-template-columns: 1fr;
  }

  .memo-section {
    min-width: unset;
  }
}
</style>
